//
//  RJOutView.m
//  AirQuality
//
//  Created by Po on 15/7/10.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJOutView.h"
#import "RJCstationMapView.h"
#import "RJHomeTopSectionView.h"

@interface RJOutView ()<RJHomeTopSectionViewDelegate>

@property (retain, nonatomic) UIButton * returnButton;
@property (retain, nonatomic) UIView * AQIContentView;
@property (retain, nonatomic) UIView * mainPollutionSection;           //主要污染物
@property (retain, nonatomic) UIView * remaindSection;                 //温馨提示
@property (retain, nonatomic) UIView * last24HourSection;              //最近24小时
@property (strong, nonatomic) RJCstationMapView * mapView;  //地图界面
@property (retain, nonatomic) RJHomeTopSectionView * segmentView;          //分段控制器

@property (assign, nonatomic) UIButton * currentButton;

@property (weak, nonatomic) UIView * lineViewSectionLine;

@property (strong, nonatomic) UILabel * pmLable;

@end

@implementation RJOutView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface
{
    [self getNavBar];
    [self getScrollView];

}

#pragma mark - function
//- (void)setWindDirect:(DirectionType)directionType
//{
//    
//    NSInteger value;
//    switch (directionType) {
//        case DirectionTypeUp:
//            value = 180;
//            break;
//        case DirectionTypeLeft:
//            value = 90;
//            break;
//        case DirectionTypeDown:
//            value = 0;
//            break;
//        case DirectionTypeRight:
//            value = 180;
//            break;
//        case DirectionTypeLeftUp:
//            value = 135;
//            break;
//        case DirectionTypeLeftDown:
//            value = 45;
//            break;
//        case DirectionTypeRightUp:
//            value = 225;
//            break;
//        case DirectionTypeRightDown:
//            value = 315;
//            break;
//        default:
//            //旋转风
//            value = -1;
//            break;
//    }
//    if (_windDirectImageView) {
//        [_windDirectImageView.layer removeAllAnimations];
//    }
//    [_pandaView addSubview:[self getWindImageView]];
//    if (value != -1) {
//        CGAffineTransform rotate = CGAffineTransformMakeRotation( value / 180.0 *  2 * M_PI );
//        [[self getWindImageView] setTransform:rotate];
//    } else {
//        CABasicAnimation * basicAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//        //position transform.rotation.z opacity
//        [basicAnim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//        [basicAnim setDuration:3];
//        [basicAnim setToValue:@(2 * M_PI)];
//        [basicAnim setFillMode:kCAFillModeForwards];
//        [basicAnim setRemovedOnCompletion:NO];
//        [basicAnim setAutoreverses:YES];
//        [basicAnim setRepeatCount:INT16_MAX];
//        [[self getWindImageView].layer addAnimation:basicAnim forKey:@"position"];
//    }
//}

- (void)freeData
{
//    if (_windDirectImageView) {
//        [_windDirectImageView.layer removeAllAnimations];
//    }
}

#pragma mark - getter

- (UIView *)getNavBar
{
    if (!_navView) {
        _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
        [_navView setBackgroundColor:SysMainColor];
        [_navView addSubview:[self getReturnButton]];
        [_navView addSubview:[self getCityNameLabel]];
        [self addSubview:_navView];
    }
    return _navView;
}

- (UIButton *)getReturnButton
{
    if (!_returnButton) {
        _returnButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 11, 63, 30)];
        [_returnButton setTitle:@"刷新" forState:UIControlStateNormal];
//        [_returnButton setImageEdgeInsets:UIEdgeInsetsMake(15, 15, 15, 45)];
        _returnButton.layer.borderWidth = 2;
        _returnButton.layer.borderColor = GetRGBColor(27, 170, 169, 1).CGColor;
        _returnButton.layer.cornerRadius = 5;
        [_returnButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [_returnButton addTarget:self action:@selector(pressUpdateButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _returnButton;
}

- (UILabel *)getCityNameLabel
{
    if (!_cityLabel) {
        _cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 50, 0, 100, 50)];
        [_cityLabel setFont:[UIFont systemFontOfSize:22]];
        [_cityLabel setTextAlignment:NSTextAlignmentCenter];
        [_cityLabel setTextColor:[UIColor whiteColor]];
    }
    return _cityLabel;
}

- (UIScrollView *)getScrollView
{
    if (!_detailScrollView) {
        _detailScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, ScreenWidth, ScreenHeight - 100)];
        [_detailScrollView setContentSize:CGSizeMake(ScreenWidth, 1500)];
        [_detailScrollView setShowsVerticalScrollIndicator:YES];
        [_detailScrollView setPagingEnabled:NO];
        [_detailScrollView addSubview:[self getPandaView]];
        [_detailScrollView addSubview:[self getMainPollutionSection]];
        [_detailScrollView addSubview:[self getBarView]];
        [_detailScrollView addSubview:[self getWarmRemaindSection]];
        [_detailScrollView addSubview:[self getWarmViewXib]];
        [_detailScrollView addSubview:[self getLast24HourSection]];
        [_detailScrollView addSubview:[self getTypeSection]];
        [_detailScrollView addSubview:[self getLineView]];
        [_detailScrollView addSubview:[self getSegmentedControl]];
        if ([RJUserData defaultRJUserData].isProvince) {
          [self showMapView];
        }
//        [_detailScrollView addSubview:[self getBottomView]];
        [self addSubview:_detailScrollView];
    }
    return _detailScrollView;
}

#pragma mark - pandaView

- (UIView *)getPandaView
{
    if (!_pandaView) {
        _pandaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 190)];
        [_pandaView addSubview:[self getBackImage]];
        [_pandaView addSubview:[self getTimeLabel]];
//        [_pandaView addSubview:[self getPositionImage]];
//        [_pandaView addSubview:[self getPositionLabel]];
        [_pandaView addSubview:[self getAQIContentView]];
    }
    return _pandaView;
}

- (UILabel *)getTimeLabel
{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 100, 0, 100, 30)];
        [_timeLabel setTextColor:[UIColor whiteColor]];
        [_timeLabel setFont:[UIFont systemFontOfSize:16]];
        [_timeLabel setText:@"时间"];
        _timeLabel.layer.shadowColor = [UIColor blackColor].CGColor;
        _timeLabel.layer.shadowOffset = CGSizeMake(0,1);
        _timeLabel.layer.shadowOpacity = 0.6;
        _timeLabel.layer.shadowRadius = 1.0;
    }
    return _timeLabel;
}

- (UILabel *)getPositionLabel
{
    if (!_positionLabel) {
        _positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 85, 20, 70, 20)];
        [_positionLabel setTextAlignment:NSTextAlignmentRight];
        [_positionLabel setFont:[UIFont systemFontOfSize:15]];
        [_positionLabel setText:@"定位失败"];
        [_positionLabel setTextColor:[UIColor whiteColor]];
        _positionLabel.layer.shadowColor = [UIColor blackColor].CGColor;
        _positionLabel.layer.shadowOffset = CGSizeMake(0,1);
        _positionLabel.layer.shadowOpacity = 0.6;
        _positionLabel.layer.shadowRadius = 1.0;
    }
    return _positionLabel;
}

- (UIImageView *)getPositionImage
{
    UILabel *loctionLable = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 126, 1, 50, 56)];
    loctionLable.text = @"所在地:";
    loctionLable.textColor = [UIColor whiteColor];
    loctionLable.layer.shadowColor = [UIColor blackColor].CGColor;
    loctionLable.layer.shadowOffset = CGSizeMake(0,1);
    loctionLable.layer.shadowOpacity = 0.6;
    loctionLable.layer.shadowRadius = 1.0;
    [_pandaView addSubview:loctionLable];
    loctionLable.font = [UIFont systemFontOfSize:15];
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 100, 22, 12, 14)];
    //所在地图标
//    [imageView setImage:[UIImage imageNamed:@"cityChoose"]];
//    imageView.layer.shadowColor = [UIColor blackColor].CGColor;
//    imageView.layer.shadowOffset = CGSizeMake(0,1);
//    imageView.layer.shadowOpacity = 0.6;
//    imageView.layer.shadowRadius = 1.0;
    return imageView;
}

- (UIImageView *)getBackImage
{
    if (!_backImageView) {
        _backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,ScreenWidth, 190)];
        [_backImageView setImage:GetImage(@"outbackimage.png")];
    }
    return _backImageView;
}

- (UIView *)getAQIContentView
{
    if (!_AQIContentView) {
        _AQIContentView = [[UIView alloc] initWithFrame:CGRectMake(20, 60, ScreenWidth - 40, 130)];
        [_AQIContentView.layer setCornerRadius:4];
        [_AQIContentView addSubview:[self getAQINumLabel]];
        [_AQIContentView addSubview:[self getAQIDetailView]];
        [_AQIContentView addSubview:[self getMainPollutionLabel]];
        //分割线
        CGRect rect = _AQIContentView.bounds;
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.frame = CGRectMake(5, rect.size.height - 40, rect.size.width / 2 + 20, 1);
        layer.fillColor = GetRGBColor(255, 255, 255, 0.6).CGColor;
        layer.backgroundColor = GetRGBColor(255, 255, 255, 0.6).CGColor;
        [layer setStrokeColor:GetRGBColor(255, 255, 255, 0.6).CGColor];
        [_AQIContentView.layer addSublayer:layer];
    }
    return _AQIContentView;
}

- (UIView *)getAQIDetailView
{
    if (!_AQIDetailView) {
        _AQIDetailView = [[UIView alloc] initWithFrame:CGRectMake(70, 0, _AQIContentView.frame.size.width - 80, 100)];
        [_AQIDetailView addSubview:[self getAQIStringLabel]];
        [_AQIDetailView addSubview:[self getWeatherLabel]];
        [_AQIDetailView addSubview:[self getAirRankLabel]];
        [_AQIDetailView addSubview:[self getWindLabel]];
//        [_AQIDetailView addSubview:[self getTempLabel]];

    }
    return _AQIDetailView;
}

- (UILabel *)getAQINumLabel
{
    if (!_AQINumLabel) {
        _AQINumLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 120,50)];
        [_AQINumLabel setTextColor:[UIColor whiteColor]];
        [_AQINumLabel setTextAlignment:NSTextAlignmentLeft];
        [_AQINumLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:60]];
        [_AQINumLabel setText:@"0"];
        _AQINumLabel.layer.shadowColor = [UIColor blackColor].CGColor;
        _AQINumLabel.layer.shadowOffset = CGSizeMake(0,1);
        _AQINumLabel.layer.shadowOpacity = 0.6;
        _AQINumLabel.layer.shadowRadius = 1.0;
    }
    return _AQINumLabel;
}

- (UILabel *)getAQIStringLabel
{
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 50, 30)];
    [label setText:@"AQI"];
    [label setFont:[UIFont systemFontOfSize:20]];
    [label setTextColor:[UIColor whiteColor]];
    [label setTextAlignment:NSTextAlignmentLeft];
    label.layer.shadowColor = [UIColor blackColor].CGColor;
    label.layer.shadowOffset = CGSizeMake(0,1);
    label.layer.shadowOpacity = 0.6;
    label.layer.shadowRadius = 1.0;
    return label;
}

- (UILabel *)getMainPollutionLabel
{
    if (!_mainPollutionLabel) {
        CGRect rect = _AQIContentView.bounds;
        _mainPollutionLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, rect.size.height - 40, rect.size.width - 20, 30)];
        [_mainPollutionLabel setTextAlignment:NSTextAlignmentLeft];
        [_mainPollutionLabel setNumberOfLines:0];
        [_mainPollutionLabel setTextColor:[UIColor whiteColor]];
        [_mainPollutionLabel setFont:[UIFont systemFontOfSize:12]];
    }
    return _mainPollutionLabel;
}

- (UILabel *)getAirRankLabel
{
    if (!_AirRankLabel) {
        _AirRankLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 55, 40, 15)];
        [_AirRankLabel setTextColor:[UIColor whiteColor]];
        [_AirRankLabel setFont:[UIFont systemFontOfSize:12]];
        [_AirRankLabel.layer setCornerRadius:2];
        [_AirRankLabel setTextAlignment:NSTextAlignmentCenter];
        [_AirRankLabel setText:@"优"];
    }
    return _AirRankLabel;
}

//天气
- (UILabel *)getWeatherLabel
{
    if (!_weatherLabel) {
        _weatherLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 40, 100, 15)];
        [_weatherLabel setFont:[UIFont systemFontOfSize:12]];
        [_weatherLabel setTextAlignment:NSTextAlignmentLeft];
        [_weatherLabel setTextColor:[UIColor whiteColor]];
    }
    return _weatherLabel;
}

//- (UILabel *)getTempLabel
//{
//    if (!_tempLabel) {
//        _tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 50, 60, 15)];
//        [_tempLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:12]];
//        [_tempLabel setTextColor:[UIColor whiteColor]];
//    }
//    return _tempLabel;
//}

- (UILabel *)getWindLabel
{
    if (!_windLabel) {
        _windLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 55, 150, 15)];
        [_windLabel setFont:[UIFont systemFontOfSize:12]];
        [_windLabel setTextAlignment:NSTextAlignmentLeft];
        [_windLabel setTextColor:[UIColor whiteColor]];
    }
    return _windLabel;
}

//- (UIImageView *)getWindImageView
//{
//    if (!_windDirectImageView) {
//        _windDirectImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, _pandaView.frame.size.height - 50, 10, 18)];
//        [_windDirectImageView setImage:[UIImage imageNamed:@"WindArror"]];
//    }
//    return _windDirectImageView;
//}
#pragma mark - mainPollution
- (UIView *)getMainPollutionSection
{
    if (!_mainPollutionSection) {
        _mainPollutionSection = [[UIView alloc] initWithFrame:CGRectMake(0, 185, ScreenWidth, 40)];
        [_mainPollutionSection addSubview:[self getSectionImage:@"OutMainPollution"]];
        
        [_mainPollutionSection addSubview:[self getMainSectionLabel:CGRectMake(25, 10, ScreenWidth, 20) title:@"污染物单位(CO:mg/m³   其他:µg/m³)"]];
//        UIButton * button = [self getButton:CGRectMake(ScreenWidth - 50, 0, 70, 40) title:@"说明>"];
//        [button.titleLabel setFont:[UIFont systemFontOfSize:15]];
//        [button addTarget:self action:@selector(pressExplainButton:) forControlEvents:UIControlEventTouchUpInside];
//        [_mainPollutionSection addSubview:button];
        UILabel *unitLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, ScreenHeight, 20)];
        unitLable.font = [UIFont systemFontOfSize:12];
        unitLable.numberOfLines = 0;
        [_mainPollutionSection addSubview:unitLable];
    }
    return _mainPollutionSection;
}

- (UIView *)getBarView
{
    if (!_barView) {
        _barView = [[UIView alloc] initWithFrame:CGRectMake(0, 240, ScreenWidth, 100)];
    }
    return _barView;
}

#pragma mark - remaindView
- (UIView *)getWarmRemaindSection
{
    if (!_remaindSection) {
        _remaindSection = [[UIView alloc] initWithFrame:CGRectMake(0, 345, ScreenWidth, 40)];
        [_remaindSection addSubview:[self getSectionImage:@"OutWarm"]];
        [_remaindSection addSubview:[self getMainSectionLabel:CGRectMake(30, 10, ScreenWidth / 2, 20) title:@"温馨小贴士"]];
        [_remaindSection.layer addSublayer:[self getSectionLineView]];
        
    }
    return _remaindSection;
}

- (UIView *)getWarmViewXib
{
    if (!_warmViewXib) {
        _warmViewXib = [[UIView alloc] initWithFrame:CGRectMake(0, 375, ScreenWidth, 100)];
    }
    return _warmViewXib;
}

#pragma mark - last24HourView
- (UIView *)getLast24HourSection
{
    if (!_last24HourSection) {
        _last24HourSection = [[UIView alloc] initWithFrame:CGRectMake(0, 470, ScreenWidth, 40)];
        [_last24HourSection addSubview:[self getSectionImage:@"OutLine"]];
        [_last24HourSection addSubview:[self getMainSectionLabel:CGRectMake(30, 10, ScreenWidth - 105, 20) title:@"小时数据变化图"]];
        [_last24HourSection.layer addSublayer:[self getSectionLineView]];
    }
    return _last24HourSection;
}
#pragma mark - showMapView
- (void)showMapView
{
    [_detailScrollView addSubview:[self getMapView]];
    [_detailScrollView bringSubviewToFront:_mapView];
}

#pragma mark -- 地图页面
- (UIView *)getMapView{
    if (!_mapView) {
        _mapView = [[RJCstationMapView alloc] initWithFrame:CGRectMake(0, 730, ScreenWidth, MapHeight)];
    }
    return _mapView;
}

- (void)removeMap
{
    [_mapView removeFromSuperview];
    _mapView = nil;
}

#pragma 分段控制器 
- (RJHomeTopSectionView *)getSegmentedControl
{
    if (!_segmentView) {
        NSArray * array = @[@"AQI",@"SO₂",@"NO₂",@"CO",@"O₃",@"PM₁₀",@"PM"];
        _segmentView = [[RJHomeTopSectionView alloc] initWithFrame:CGRectMake(0, 730+MapHeight, ScreenWidth, 35) titles:array];
        [_segmentView setSelectCount:0];
        [_segmentView setDelegate:self];
    }
    return _segmentView;
}

- (BOOL)HomeTopSectionView:(RJHomeTopSectionView *)sectionView didSelectCount:(NSUInteger)count isLeft:(BOOL)isLeft
{
    NSArray * array = @[@"AQI",@"SO₂",@"NO₂",@"CO",@"O₃",@"PM₁₀",@"PM"];
    NSArray * maparray = @[@"AQI",@"SO2",@"NO2",@"CO",@"O3",@"PM10",@"PM2_5"];
    NSString * type = array[count];
    NSString * mapType = maparray[count];
    if (_delegate) {
        [_delegate changeMapAndBottomWithType:type];
    }
    [_mapView changePointWithType:mapType];
    return YES;
}

- (void)mapViewChangedWithCityName:(NSString *)cityName cityCode:(NSString *)cityCode
{
    [_mapView reloadView:YES cityName:cityName cityCode:cityCode];
}

- (UIView *)getTypeSection
{
    if (!_typeSection) {
        _typeSection = [[UIView alloc] initWithFrame:CGRectMake(0, 510+175, ScreenWidth, 40)];
        [_typeSection setBackgroundColor:GetRGBColor(245, 245, 245, 1)];
        NSArray * titles = @[@"AQI",@"SO₂",@"NO₂",@"CO",@"O₃",@"PM₁₀",@"PM"];
        CGFloat buttonWidth = ScreenWidth / titles.count;
        float a[7] = {buttonWidth,buttonWidth,buttonWidth,buttonWidth-5,buttonWidth-6,buttonWidth,buttonWidth+6};
        CGFloat buttonX = 0;
        for (NSUInteger i = 0; i < titles.count; i ++) {
            UIButton * button = [self getTypeSectionButton:CGRectMake(buttonX, 0, buttonWidth, 40) title:titles[i]];
            CGFloat height = button.frame.size.height;
            if ([titles[i] isEqualToString:@"PM"]) {
                _pmLable = [[UILabel alloc] init];
                _pmLable.text = @"2.5";
                _pmLable.frame = CGRectMake(buttonWidth/2+11, height/3+2, 20, 20);
                _pmLable.font = [UIFont systemFontOfSize:9];
                [button addSubview:_pmLable];
            }
            [button.titleLabel setFont:[UIFont systemFontOfSize:15]];
            [_typeSection addSubview:button];
            if (i == 0) {
                [button setSelected:YES];
                _currentButton = button;
            }
             buttonX += a[i];
        }
       UIView * lineViewSectionLine = [[UIView alloc] initWithFrame:CGRectMake(0, 38, ScreenWidth / titles.count, 2)];
        _lineViewSectionLine = lineViewSectionLine;
        [_lineViewSectionLine setBackgroundColor:SysMainColor];
        [_typeSection addSubview:_lineViewSectionLine];
    }
    [_detailScrollView bringSubviewToFront:_typeSection];
    return _typeSection;
}

- (UIButton *)getTypeSectionButton:(CGRect)frame title:(NSString *)title
{
    UIButton * button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:GetRGBColor(85, 85, 85, 1) forState:UIControlStateNormal];
    [button setTitleColor:SysMainColor forState:UIControlStateSelected];
    [button addTarget:self action:@selector(pressTypeButton:) forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (UIView *)getLineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 550, ScreenWidth, 200)];
    }
    return _lineView;
}



#pragma mark - public
- (UIImageView *)getSectionImage:(NSString *)imageName
{
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
    [imageView setImage:[UIImage imageNamed:imageName]];
    return imageView;
}

- (UILabel *)getMainSectionLabel:(CGRect)frame title:(NSString *)title
{
    UILabel * label = [[UILabel alloc] initWithFrame:frame];
    [label setTextColor:GetRGBColor(85, 85, 85, 1)];
    NSString * titleString = [[NSString stringWithFormat:@" "] stringByAppendingString:title];
    if (titleString.length >= 27) {
        NSUInteger length = titleString.length;
        NSUInteger index = [titleString rangeOfString:@"("].location;
        NSMutableAttributedString * attr = [[NSMutableAttributedString alloc] initWithString:titleString];
        [attr addAttribute:NSFontAttributeName
                     value:[UIFont systemFontOfSize:12.0]
                     range:NSMakeRange(index,length-index)];
        [label setAttributedText:attr];
        return label;
    }
    label.font = [UIFont systemFontOfSize:16];
    [label setText:titleString];
    return label;
}

- (UIButton *)getButton:(CGRect)frame title:(NSString *)title
{
    UIButton * button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:GetRGBColor(85, 85, 85, 1) forState:UIControlStateNormal];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 20)];
    return button;
}

- (CAShapeLayer *)getSectionLineView
{
    CAShapeLayer * layer = [CAShapeLayer layer];
    [layer setBackgroundColor:SysMainColor.CGColor];
    [layer setFrame:CGRectMake(0, 0, ScreenWidth, 1)];
    return layer;
}

#pragma mark - event
- (void)pressUpdateButton:(UIButton *)sender
{
    if (_delegate) {
        [_delegate OutView:self pressUpdateButton:sender];
    }
}

- (void)pressExplainButton:(UIButton *)sender
{
    if (_delegate) {
        [_delegate OutView:self pressExplainButton:sender];
    }
}


- (void)pressTypeButton:(UIButton *)sender
{
    if (_currentButton == sender) {
        return;
    }
    
    if ([sender.titleLabel.text isEqualToString:@"PM"]) {
        _pmLable.textColor = GetRGBColor(34, 187, 185, 1);
    }else{
      _pmLable.textColor = [UIColor blackColor];
    }
    
    CGRect lineRect = _lineViewSectionLine.frame;
    lineRect.origin.x = sender.frame.origin.x;
    [UIView animateWithDuration:0.2 animations:^{
        [_lineViewSectionLine setFrame:lineRect];
    }];
    
    [_currentButton setSelected:NO];
    _currentButton = sender;
    [_currentButton setSelected:YES];
    if (_delegate) {
        [_delegate OutView:self pressTypeButton:sender];
    }
}

- (void)typeSectionUpdata
{
    for (UIView * view in [_typeSection subviews]) {
        [view removeFromSuperview];
    }
    [_typeSection removeFromSuperview];
    _typeSection = nil;
    [_detailScrollView addSubview:[self getTypeSection]];
    for (UIView * view in [_segmentView subviews]) {
        [view removeFromSuperview];
    }
    [_segmentView removeFromSuperview];
    _segmentView = nil;
    [_detailScrollView addSubview:[self getSegmentedControl]];
    [_mapView changePointWithType:@"AQI"];
}
@end
